#!/bin/bash

OSNICK=`/opt/redislabs/bin/python2 /opt/RedisGears/deps/readies/bin/platform --osnick`
[[ $OSNICK =~ 'rhel7' ]] && OSNICK='centos7'
if [[ $OSNICK != 'centos7' && $OSNICK != 'bionic' && $OSNICK != 'xenial' ]]; then
	echo "$OSNICK: incompatible platform. Aborting."
	exit 1
fi

MOD_DIR=/opt/recipe/rs
/opt/redislabs/bin/python2 $MOD_DIR/install-modules.py --no-bootstrap-check --yaml $MOD_DIR/redis-modules-$OSNICK.yaml
 
module=$(yq .redisgears.awspath $MOD_DIR/redis-modules-$OSNICK.yaml | cut -d\" -f2)
mod_json=$(curl -k \
	-u "${USER}:${PASSWD}" \
	-F "module=@/opt/redislabs/lib/modules/$module" \
	https://localhost:9443/v1/modules)
